package com.ricervcvcer.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ricervcvcer.order.entity.OrderStatusEntity;
import com.ricervcvcer.order.mapper.OrderStatusDao;
import com.ricervcvcer.order.service.OrderService;
import com.ricervcvcer.order.service.OrderStatusService;
import com.ricervcvcer.order.util.PageUtils;
import com.ricervcvcer.order.util.Query;
import com.ricervcvcer.order.vo.OrderStatusVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


@Service("orderStatusService")
public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusDao, OrderStatusEntity> implements OrderStatusService {

    @Autowired
    OrderService orderService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderStatusEntity> page = this.page(
                new Query<OrderStatusEntity>().getPage(params),
                new QueryWrapper<OrderStatusEntity>()
        );

        return new PageUtils(page);
    }
    @Transactional
    @Override
    public void updateByOrderId(OrderStatusVo orderStatusVo) {
        OrderStatusEntity orderStatusEntity = new OrderStatusEntity();
        BeanUtils.copyProperties(orderStatusVo, orderStatusEntity);
        boolean b1 = this.updateById(orderStatusEntity);

        boolean b = orderService.updateById(orderStatusVo);

        if(!(b && b1))
            throw new RuntimeException("发货失败！");

    }

}